package com.framework.yhbapi.controller;

import com.framework.exception.util.RespResult;
import com.framework.service.yhbservice.YhbUserBankService;
import com.framework.yhbEntity.user.YhbUserBank;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 功能描述: 银行卡信息控制器
 *
 * @author ck
 * @date 2018/9/18 11:48
 */
@RestController
@Api(value="银行卡信息模块",tags={"银行卡信息模块"})
@RequestMapping(value = "yhbBank")
public class YhbBankController {

	@Autowired
	private YhbUserBankService yhbUserBankService;


	/**
	 * 添加银行卡信息
	 * @param bank 银行卡
	 * @param vCode 验证码
	 * @param token 登录人token
	 * @return
	 */
	@PostMapping("user/insertBank")
	@ApiOperation("添加银行卡信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name="vCode",value="验证码",dataType="string", paramType = "query" ,required = true),
			@ApiImplicitParam(name="token",value="登录产生的token",dataType="String", paramType = "query",required = true),
			@ApiImplicitParam(name="bank",value="银行卡对象",dataType="com.framework.yhbEntity.user.YhbUserBank", paramType = "query" ,required = true)
	})
	public RespResult insertBank(YhbUserBank bank, String vCode, String token,String password,String confPassword,String identity) {
		yhbUserBankService.insertBank(bank,vCode,token,password,confPassword,identity);

		return RespResult.ok();
	}
	/**
	 * 修改银行卡信息
	 * @param bank 银行卡
	 * @param vCode 验证码
	 * @param token 登录人token
	 * @return
	 */
	@PostMapping("user/updateBank")
	@ApiOperation("修改银行卡信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name="vCode",value="验证码",dataType="string", paramType = "query" ,required = true),
			@ApiImplicitParam(name="token",value="登录产生的token",dataType="String", paramType = "query",required = true),
			@ApiImplicitParam(name="bank",value="银行卡对象",dataType="com.framework.yhbEntity.user.YhbUserBank", paramType = "query" ,required = true)
	})
	public RespResult updateBank(YhbUserBank bank,String vCode,String token){
		yhbUserBankService.updateBank(bank,vCode,token);
		return RespResult.ok();
	}

	/**
	 * 获取默认银行卡
	 * @param token 登录人token
	 * @return
	 */
	@PostMapping("user/getDefaultBank")
	@ApiOperation("获取默认银行卡")
	@ApiImplicitParam(name="token",value="登录产生的token",dataType="String", paramType = "query",required = true)
	public RespResult getDefaultBank(String token){
		YhbUserBank bank = yhbUserBankService.queryDefaultBankByToken(token);
		return RespResult.ok().put("bank",bank);
	}


	/**
	 * 获取银行卡详情
	 * @param token 登录人token
	 * @param bankId 银行卡id
	 * @return
	 */
	@GetMapping("user/infoBankById")
	@ApiOperation("获取银行卡详情")
	@ApiImplicitParams({
			@ApiImplicitParam(name="bankId",value="银行卡id",dataType="long", paramType = "query" ,required = true),
			@ApiImplicitParam(name="token",value="登录产生的token",dataType="String", paramType = "query",required = true)
	})
	public RespResult infoBankById(String token,Long bankId) {
		YhbUserBank info = yhbUserBankService.infoBank(token, bankId);
		return RespResult.ok().put("bank",info);
	}

	/**
	 * 删除银行卡信息
	 * @param bankId 银行卡id
	 * @return
	 */
	@PostMapping("user/delBankById")
	@ApiOperation("删除银行卡信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name="bankId",value="银行卡id",dataType="long", paramType = "query" ,required = true),
	})
	public RespResult delBankById(Long bankId) {
		yhbUserBankService.delBank(bankId);
		return RespResult.ok();
	}

	/**
	 * 银行卡列表
	 * @return
	 */
	@PostMapping("user/queryBankList")
	@ApiOperation("银行卡列表")
	@ApiImplicitParam(name="token",value="登录产生的token",dataType="String", paramType = "query",required = true)
	public RespResult queryBankList(String  token) {
		List<YhbUserBank> list = yhbUserBankService.queryBankListByToken(token);
		return RespResult.ok().put("list",list);
	}

	/**
	 *
	 * @param bankNo
	 * @return
	 */
	@GetMapping("/queryBankNameByNo")
	@ApiOperation("根据银行卡号获取银行卡名称")
	@ApiImplicitParam(name="bankNo",value="银行卡号",dataType="String", paramType = "query",required = true)
	public RespResult queryBankNameByNo(String bankNo){
		Map<String,Object> map=yhbUserBankService.queryBankNameByNo(bankNo);
		return RespResult.ok(map);
	}

}
